# -*- coding: utf-8 -*-
# @Time : 2021/9/17 14:25
# @Author : 阿怪
# @Email : 673691277@qq.com
# @File : swipe.py
# @Project : mryx_test
'''滑动类'''

class Swipe():
    '''滑动类，包括四个滑动方向'''

    def __init__(self,driver):
        self.driver = driver
        self.size = self.driver.get_window_size()
        self.width = self.size.get('width')
        self.height = self.size.get('height')

    def left_swipe(self,start_percent=0.8,end_percent=0.1,h_percent=0.3,duration=2):
        '''向左滑动'''
        s_x = self.width * start_percent
        e_x = self.width * end_percent
        e_y = s_y = self.height * h_percent
        self.driver.swipe(s_x,s_y,e_x,e_y,duration*1000)

    def right_swipe(self,start_percent=0.1,end_percent=0.8,h_percent=0.3,duration = 2):
        '''向右滑动'''
        s_x = self.width * start_percent
        e_x = self.width * end_percent
        e_y = s_y = self.height * h_percent
        self.driver.swipe(s_x,s_y,e_x,e_y,duration*1000)

    def up_swipe(self,width_percent=0.5,start_height_percent=0.85,end_height_percent=0.2,duration = 2):
        '''向上滑动'''
        s_x = e_x = self.width * width_percent
        s_y = self.height * start_height_percent
        e_y = self.height * end_height_percent
        self.driver.swipe(s_x,s_y,e_x,e_y,duration*1000)

    def down_swipe(self,width_percent=0.5,start_height_percent=0.2,end_height_percent=0.9,duration = 2):
        '''向下滑动'''
        s_x = e_x = self.width * width_percent
        s_y = self.height * start_height_percent
        e_y = self.height * end_height_percent
        self.driver.swipe(s_x,s_y,e_x,e_y,duration*1000)

    def flick_left(self,start_percent=0.8,end_percent=0.1,h_percent=0.3):
        self.left_swipe(start_percent=start_percent,end_percent=end_percent,h_percent=h_percent,duration=0)


